<template>
  <div class="userList">
    <button type="primary" @click="handleClick">获取服务端时间</button>

    <p>call from server:{{ msg }}</p>

    <p @click="vuexclick">click here</p>
    <p>{{ $store.state.ap.servernow }}</p>
    <p>{{ servernow }}</p>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      msg: ''
    }
  },
  computed: {
    servernow() {
      return this.$store.state.ap.servernow
    }
  },
  methods: {
    vuexclick: () => {
      console.log(this)
      axios.get('http://localhost:5000/api/Values/now').then(r => {
        this.$store.commit('ap/SERVERNOW', r.data)
      })
    },
    handleClick(evt) {
      const _self = this
      axios
        .get('http://localhost:5000/api/Values/now')
        .then(function(response) {
          // debugger;

          console.log(response)

          _self.msg = response.data
        })
        .catch(function(error) {
          console.log(error)
        })
    }
  }
}
</script>
<style scoped>
.userList {
  padding-top: 10px;
}
</style>
